<template>
	<view :style="{'min-height':minH,'background-color':'#ffffff'}">
		<view class="order-list">
			<!-- 头部分类bar start -->
			<view class="order-bar">
				<my-tabs @change="tapChange" :modelData="orderTabs" :initIndex="initIndex"></my-tabs>
			</view>
			<!-- 订单列表 start -->
			<view class="order-list-item">
				<mescroll-body ref="mescrollRef" :down="downOption" @init="mescrollInit" @down="downCallback" :up="upOption" @up="upCallback">
					
				</mescroll-body>
			</view>
			<!-- 订单列表 end -->
		</view>
	</view>
</template>

<script>
	import myTabs from '@/components/myTabs/myTabs.vue'
	import {getOrderPage} from '@/api/order.js'
	import {globalMixin} from '@/util/globalMixin.js'
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins:[globalMixin,MescrollMixin],
		components: {
			myTabs
		},
		data() {
			return {
				winH: 0,
				initIndex:0,
				statusToIndex: {
					1:1,
					2:2,
					3:3,
					4:4,
				},
				orderTabs: [
					{label:"全部",value:1},
					{label:"确认中",value:2},
					{label:"已发货",value:3},
					{label:"已完成",value:4},
					{label:"退货",value:5},
				],
				searchEnd: true,
				orderList: [],
				searchParam:{},
				downOption: {
					auto: false //是否在初始化后,自动执行downCallback; 默认true
				},
				upOption:{
					noMoreSize: 4, 
					empty:{
						tip: '~ 搜索无商品 ~',
						btnText: '去看看'
					}
				},
			}
		},
		onLoad(option) {
			this.initH();
			if(option.status) {
				this.initIndex = this.statusToIndex[option.status]
			}
			//this.refresh();
		},
		computed: {
			minH: function(){
				return this.winH+"px"
			}
		},
		methods: {
			/*下拉刷新的回调 */
			downCallback() {
				//联网加载数据
				this.findOrderList()
			},
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			upCallback(page) {
				this.searchParam.page = page.num
				this.searchParam.page_size = page.size
				this.findOrderList(true)
			},
			tapChange: function(val,item) {
				this.initIndex=val
				this.downCallback()
			},
			findOrderList(isUp) {
				getOrderPage({...this.searchParam,status:this.initIndex,order_field:'uid',order_type:'desc'}).then(res=>{
					if(res.code== 0) {
						let items = res.data.items || []
						this.mescroll.endSuccess();
						this.mescroll.endBySize(items.length || 0 , res.data.total_result || 0);
						if(isUp) {
							this.orderList = this.orderList.concat(items);
						} else {
							this.orderList = items
						}
					} else {
						this.orderList = []
						this.mescroll.endErr();
					}
				}).catch(()=>{
					//联网失败的回调,隐藏下拉刷新的状态
					this.mescroll.endErr();
				})
			},
			initH () {
				let _self = this
				uni.getSystemInfo({
				    success: function (res) {
						_self.winH = res.windowHeight
						console.log(_self.winH)
				    }
				});
			}
		}
	}
</script>

<style scoped lang="scss">
.order-list {
	padding: 20rpx 40rpx;
}
.no-data {
	height: 180rpx;
	.sl-box {
		width: 100%;
		text-align: center;
		.no-img {
			image {
				height: 96rpx;
				width: 96rpx;
			}
		}
		.no-desc {
			font-size: 36rpx;
			margin-top: 20rpx;
			color: #aaa;
		}
	}
}
</style>
